<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="./index.css">
</head>

<body>
    <div class="content">
        <div class="top">
            <ol>
                <li class="tab-list">扫地机</li>
                <li>空净</li>
                <li>清洁</li>
                <li>风扇</li>
            </ol>
        </div>
        <div>
            <ul>

            </ul>
        </div>
    </div>
    <script src="./a.js"></script>
    <script>
        /* console.log(arr);
        console.log(arr[0]);
        console.log(arr[0].data);
        console.log(arr[0].data[0]);
        console.log(arr[0].data[0].title);
        console.log(arr[0].data[0].url);
        console.log(arr[0].data[0].desc);
        console.log(arr[0].data[0].price); */
        var str = '';

        for (var i = 0; i < arr[0].data.length; i++) {
            var obj = arr[0].data[i];
            str += `<li>
                   <img src = '${obj.url}'>
                   <h5>${obj.title}</h5>
                   <span>${obj.desc}</span>
                   <p>${obj.price}元<s>${parseInt(obj.price * 1.1)}元</s></p>
                   </li>`
        }

        let ul = document.querySelector('ul');
        let ol = document.querySelectorAll('ol>li');
        ul.innerHTML = str;
        for (let j = 0; j < ol.length; j++) {
            ol[j].setAttribute('index', i);
            ol[j].onmouseenter = function () {
                for (let k = 0; k < ol.length; k++) {
                    ol[k].className = '';
                }
                this.className = 'tab-list';

                var str = '';

                for (var i = 0; i < arr[j].data.length; i++) {
                    var obj = arr[j].data[i];
                    str += `<li>
                   <img src = '${obj.url}'>
                   <h5>${obj.title}</h5>
                   <span>${obj.desc}</span>
                   <p>${obj.price}元<s>${parseInt(obj.price * 1.1)}元</s></p>
                   </li>`
                    ul.innerHTML = str;
                }
            }
        }
    </script>
</body>

</html>